﻿using Microsoft.AspNetCore.Mvc;
using Project.Yan.Net.BLL;
using Project.Yan.Net.BLL.DTOs;
using Project.Yan.Net.DAL.Entities;
using Project.Yan.Net.Filters;
using Project.Yan.Net.Models;
using Project.Yan.Net.Tool.Log;
using Project.Yan.Net.Tool.Mapster;

namespace Project.Yan.Net.Controllers
{
    /// <summary>
    /// 
    /// </summary>
    [ApiController]
    [Route("/api/[controller]/[action]")]
    [ApiResult]
   // [TypeFilter(typeof(GlobalExceptionMiddleware))]
    public class UserController : ControllerBase
    {
        private readonly UserService _userService;
        private readonly ILoggerService _loggerService;
        public UserController(UserService userService, ILoggerService loggerService)
        {
            _userService = userService;
            _loggerService = loggerService;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<UserViewModel> GetUserById(int userId)
        {
            var result = await _userService.GetUser(userId);
            var userViewModel = MapperHelper.Map<UserDTO, UserViewModel>(result);
            return userViewModel;

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<UserViewModel> GetUserCacheById(int userId)
        {
            var result = await _userService.GetUserCacheById(userId);
            var userViewModel = MapperHelper.Map<UserDTO, UserViewModel>(result);
            return userViewModel;

        }
     
        [HttpGet]
        public async Task<UserViewModel> GetUserByEmail(string email)
        {
            var result = await _userService.GetUserByEmail(email);
            var userViewModel = MapperHelper.Map<UserDTO, UserViewModel>(result);
            return userViewModel;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string LogTest()
        {
            _loggerService.LogInformation("hello");
            return "111";
        }
    }
}
